import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'  //vue3写法，都是一些路由的常用方法
import useStore from '@/store';  //导入store，从中获取用户路由信息，在注销系统时，依据此注销对应路由
// import useStore from "@/store";  //导入这个做什么?
export const Layout = () => import('@/layout/index.vue')  //这个你不飘红？我没有这个文件夹呀   这两个先不要先


// 静态路由列表
export const constantRoutes: Array<RouteRecordRaw> = [
    {
      path: '/',
      component: Layout,
      meta: { hidden: true },
      children: [
        // {
        //   path: 'dashboard',
        //   component: () => import('@/views/dashboard/index.vue'),
        //   name: 'Dashboard',
        //   meta: { title: 'dashboard', icon: 'homepage', affix: true }
        // },
        {
          path: '401',
          component: () => import('@/views/error-page/401.vue'),
          meta: { hidden: true }
        },
      ]
    },
    // {
    //   path: '/',
    //   component: ()=> import('@/views/login/index.vue'),
    //   meta: { hidden: true },
    // },
    // {
    //   path: '/',
    //   component: ()=> import('@/layout/index.vue'),
    //   meta: { hidden: true },
    //   children: [
    //     {
    //       path: 'role',
    //       component: () => import('@/views/system/role/index.vue')
    //     },
    //     {
    //       path: 'department',
    //       component: () => import('@/views/system/department/index.vue')
    //     }
    //   ]
    // },
    // {
    //   path: '/login',
    //   component: () => import('@/views/login/index.vue'),
    //   meta: { hidden: true }
    // },
    {
      path: '/login',
      name:'login',
      component: () => import('@/views/login/index.vue'),
      meta: { hidden: true }
    },
    // {
    //   path: '/role',
    //   component: ()=> import('@/views/login/index.vue'),
    //   meta: { hidden: true },
    // },
  ];

// 创建路由
const router = createRouter({
    history: createWebHashHistory(),
    routes: constantRoutes as RouteRecordRaw[],
    // 刷新时，滚动条位置还原
    scrollBehavior: () => ({ left: 0, top: 0 })
  });

// 重置路由
export function resetRouter() {
  const { permission } = useStore();
  console.log("总的路由")
  console.log(router)
  console.log("准备注销的路由")
  console.log(permission.routes)
  permission.routes.forEach(route => {
    console.log("注销三次")
    const name = route.name;
    console.log("路由名称" + name)
    if (name && name != 'login' && router.hasRoute(name)) {
      router.removeRoute(name);  //注销路由
    }
  });
  permission.addRoutes = [];  //清空permission stroe中的路由列表
}


export default router;